import React, { Component } from 'react';
import Husband from './components/Husband';
import Wife from './components/Wife';

export default class App extends Component {
  // 1、将丈夫的state提升到app组件中，再父传子money
  state = {
    money: 1,
  };

  /* 赚钱方法 */
  handleMakeMoney = () => {
    this.setState({ money: this.state.money + 1000 });
  };

  // 花钱方法
  handleCost = (num) => {
    this.setState({ money: this.state.money - num });
  };

  render() {
    const { money } = this.state;
    return (
      <div>
        <h1 style={{ textAlign: 'center' }}>家庭存款：</h1>
        <Husband money={money} handleMakeMoney={this.handleMakeMoney}></Husband>
        <hr />
        <Wife handleCost={this.handleCost}></Wife>
      </div>
    );
  }
}
